<?php

namespace App\Models\Game\User;

use App\Models\Game\Model;
use App\Models\Game\Platform\Org;
use App\Models\Game\Player\Player;
use App\Models\Game\Player\PlayerFish;
use App\Models\Game\Player\PlayerSlo;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;

class User extends Model
{

    /**
     * 数据表名称
     *
     * @var string
     */
    protected $table = 't_user';

    /**
     * 查询后隐藏的字段
     *
     * @var array
     */
    protected $hidden = [
        'password'
    ];

    /**
     * 是否主动维护时间戳
     *
     * @var bool
     */
    public $timestamps = false;

    /**
     * 获取用户角色
     *
     * @param int|null $value
     * @return array
     */
    public function getRoleAttribute(?int $value): array
    {
        return decimal_to_binary_bits($value);
    }

    /**
     * 获取访问控制
     *
     * @param int|null $value
     * @return array
     */
    public function getAccessAttribute(?int $value): array
    {
        return decimal_to_binary_bits($value);
    }

    /**
     * 获得平台信息
     *
     * @return BelongsTo
     */
    public function org(): BelongsTo
    {
        return $this->belongsTo(Org::class, 'plat_code', 'code')->withTrashed();
    }

    /**
     * 获得钱包信息
     *
     * @return HasOne
     */
    public function wallet(): HasOne
    {
        return $this->hasOne(UserWallet::class, 'id', 'id');
    }

    /**
     * 获得【player】信息
     *
     * @return HasOne
     */
    public function player(): HasOne
    {
        return $this->hasOne(Player::class, 'id', 'id');
    }

    /**
     * 获得【player_slo】信息
     *
     * @return HasOne
     */
    public function playerSlo(): HasOne
    {
        return $this->hasOne(PlayerSlo::class, 'id', 'id');
    }

    /**
     * 获得【player_fish】信息
     *
     * @return HasOne
     */
    public function playerFish(): HasOne
    {
        return $this->hasOne(PlayerFish::class, 'id', 'id');
    }
}
